package com.ghck.message.event;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ghck.message.service.JpushService;
import com.ghck.message.util.PushUtil;

@Component
public class JpushMessageListener implements ApplicationListener<JpushMessageEvent> {

	Logger logger = LoggerFactory.getLogger(JpushMessageListener.class);
	
	@Autowired
	private JpushService jpushService;
	
	@Override
	public void onApplicationEvent(JpushMessageEvent event) {
		logger.info("JpushMessageListener begin,event is "+JSON.toJSONString(event));
		try{
			if(event==null||event.getMessage()==null){
				return;
			}
			long start = System.currentTimeMillis();
			PushUtil.sendMessage(event.getMessage());
			long end = System.currentTimeMillis();
			logger.info("推送结束，耗时:{}.ms",(end-start));
		}catch(Exception e){
			logger.error("JpushMessageListener error,err msg is {}",e.getMessage());
		}
	
	}

}
